package com.islewars.client;

import java.util.List;
import java.util.Random;

import com.islewars.client.dto.MountainDto;

public class Calculation {
	public static double getHeight(Vector position, List<MountainDto> mountains) {
		double height = 0.0;
		
		for (MountainDto mountain : mountains) {
			double distance = Vector.sub(position, mountain).mag();
			if (distance<mountain.radius) {
				if (mountain.type.equals(MountainType.MOUNTAIN)) {
					double calc = mountain.radius*3000.0/Math.pow(Vector.sub(position, mountain).mag(), 2);
					if (calc>mountain.height) {
						calc = mountain.height;
					}
					height += calc;
				} else if (mountain.type.equals(MountainType.CONE)) {
					height += mountain.height*(mountain.radius-distance)/mountain.radius;
				} else if (mountain.type.equals(MountainType.HILL)) {
					height += mountain.height*(mountain.radius*mountain.radius - Vector.sub(position, mountain).magSquared())/(mountain.radius*mountain.radius);
				}
			}
		}

		Random rn = new Random();
		height += rn.nextDouble()*10.0;
		
		if (height>500) {
			height=500;
		}
		return height;
	}
}
